package class_object;

public class MethodOverloadDemo {
    // 1. 不同参数数量
    public int add(int a, int b) {
        System.out.println("两个int参数的add方法");
        return a + b;
    }

    public int add(int a, int b, int c) {
        System.out.println("三个int参数的add方法");
        return a + b + c;
    }

    // 2. 不同参数类型
    public double add(double a, double b) {
        System.out.println("两个double参数的add方法");
        return a + b;
    }

    public String add(String a, String b) {
        System.out.println("两个String参数的add方法");
        return a + b;
    }

    // 3. 不同参数顺序（参数类型不同时才有意义）
    public void showInfo(String name, int age) {
        System.out.println("姓名：" + name + "，年龄：" + age);
    }

    public void showInfo(int age, String name) {
        System.out.println("年龄：" + age + "，姓名：" + name);
    }

    public static void main(String[] args) {
        MethodOverloadDemo demo = new MethodOverloadDemo();

        System.out.println(demo.add(1, 2));
        System.out.println(demo.add(1, 2, 3));
        System.out.println(demo.add(1.5, 2.5));
        System.out.println(demo.add("Hello", "World"));

        demo.showInfo("张三", 25);
        demo.showInfo(30, "李四");
    }
}
